package view;

import controller.ControlPanel;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import model.ArtikelFilm;
import model.Datadrager;
import model.Genre;
import model.Klant;
import model.Uitvoering;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
 * View van Filmspaneel.
 * 
 */
public class Films extends javax.swing.JPanel {

    private ControlPanel controlpanel = null;
    private Klant klant;
    List<ArtikelFilm> lijst;

    /**
     * Creates new form Films, zonder dat er een klant is gezocht.
     *
     * @param controlpanel
     */
    public Films(ControlPanel controlpanel) {
        initComponents();
        this.controlpanel = controlpanel;
        this.populateComboBoxes();
//        if (klant == null) {
        jBTReserveren.setEnabled(false);
        jBTVerhuren.setEnabled(false);
//        }
    }

    /**
     * Create a new form, met gezochte klant
     * @param controlpanel
     * @param klant 
     */
    public Films(ControlPanel controlpanel, Klant klant) {
        initComponents();
        this.controlpanel = controlpanel;
        this.klant = klant;
        this.populateComboBoxes();
        this.populateKlantVelden();
    }

    /**
     * Voorziet de klantvelden van data uit klant object.
     */
    public void populateKlantVelden() {
        jTFKlantNummer.setText("" + klant.getKlantnummer());
        jTFToonVoornaam.setText(klant.getNaam());
        jTFToonAchternaam.setText(klant.getAchternaam());
        jTFToonAdres.setText(klant.getStraat());
        jTFToonHuisnummer.setText(klant.getHuisnummer());
        jTFToonWoonplaats.setText(klant.getWoonplaats());
        jTFToonTelefoonnummer.setText(klant.getTelefoonnummer());
    }

    /**
     * Voorziet de comboboxen van enum waarden.
     */
    public void populateComboBoxes() {
        jCBzoekGenre.addItem("Selecteer");
        jCBzoekGenre.addItem(Genre.ACTIE);
        jCBzoekGenre.addItem(Genre.DRAMA);
        jCBzoekGenre.addItem(Genre.KOMEDIE);
        jCBzoekGenre.addItem(Genre.ROMANTIEK);

        jCBzoekUitvoering.addItem("Selecteer");
        jCBzoekUitvoering.addItem(Uitvoering.BIOSCOOP_VERSIE);
        jCBzoekUitvoering.addItem(Uitvoering.DIRECTORS_CUT);
        jCBzoekUitvoering.addItem(Uitvoering.EXTENDED_VERSION);

        jCBzoekDatadrager.addItem("Selecteer");
        jCBzoekDatadrager.addItem(Datadrager.BLURAY);
        jCBzoekDatadrager.addItem(Datadrager.DVD);
    }
    
    /**
     * Zet alle data uit lijst collectie in tabellen.
     * @param lijst 
     */
    public void updateTables(List<ArtikelFilm> lijst) {
        TableModel model;
        TableModel modelnb;

        DefaultTableModel dmr = (DefaultTableModel) jTFilms.getModel();
        dmr.getDataVector().removeAllElements();
        dmr.fireTableDataChanged();

        if (lijst.size() > 0) {

            List<String> columns = new ArrayList<String>();
            List<String[]> values = new ArrayList<String[]>();
            List<String> columnsnb = new ArrayList<String>();
            List<String[]> valuesnb = new ArrayList<String[]>();

            columns.add("Artikelnummer");
            columns.add("Titel");
            columns.add("Uitvoering");
            columns.add("Medium");
            columnsnb.add("Artikelnummer");
            columnsnb.add("Titel");
            columnsnb.add("Uitvoering");
            columnsnb.add("Medium");
            columnsnb.add("Gereserveerd tot");
            columnsnb.add("Verhuurd tot");
            

            for (ArtikelFilm af : lijst) {
                String artikelnr = "" + af.getArtikelNummer();
                String gereserveerdTot = "";
                String verstrijkDatum = "";
                java.sql.Date gereserveerdOp;
                
                boolean isGereserveerd = controlpanel.getReservingStatus(Integer.parseInt(artikelnr));
                boolean isVerhuurd = controlpanel.getVerhuurStatus(af.getArtikelNummer());
                if (!isGereserveerd && !isVerhuurd) {
                    values.add(new String[]{artikelnr, af.getTitel(), af.getUitvoering().toString(), af.getDatadrager().toString()});
                }else{
                    if (isGereserveerd) {
                        gereserveerdOp = new java.sql.Date(new java.util.Date().getTime());
                        gereserveerdTot = new java.sql.Date(gereserveerdOp.getTime() + (1000 * 60 * 60 * 24)).toString();

                    }else{
                        verstrijkDatum = controlpanel.zoekVerstrijkDatum(af.getArtikelNummer());
                    }                    
                   if ( verstrijkDatum == "" ) {
                       verstrijkDatum = "niet verhuurd";
                   }
                   if ( gereserveerdTot == "" ) {
                       gereserveerdTot = "niet gereserveerd";
                   }
                   valuesnb.add(new String[]{artikelnr, af.getTitel(), af.getUitvoering().toString(), af.getDatadrager().toString(), gereserveerdTot, verstrijkDatum});
                }
            }

            model = new DefaultTableModel(values.toArray(new Object[][]{}), columns.toArray());
            modelnb = new DefaultTableModel(valuesnb.toArray(new Object[][]{}), columnsnb.toArray());

            jTFilms.setModel(model);
            jTNietBeschikbaar.setModel(modelnb);
            if ( klant != null ) {
                this.jBTReserveren.setEnabled(true);
                this.jBTVerhuren.setEnabled(true);
            }
        } else {
            jBTReserveren.setEnabled(false);
            jBTVerhuren.setEnabled(false);
        }
        jTNietBeschikbaar.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTFToonAdres = new javax.swing.JTextField();
        jTFToonAchternaam = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTFToonVoornaam = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jBTZoek = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTFToonHuisnummer = new javax.swing.JTextField();
        jTFToonWoonplaats = new javax.swing.JTextField();
        jTFToonTelefoonnummer = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTFZoekProducent = new javax.swing.JTextField();
        jTFZoekTitel = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTFZoekArtikelNummer = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTFKlantNummer = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTFilms = new javax.swing.JTable();
        jLabel16 = new javax.swing.JLabel();
        jBTVerhuren = new javax.swing.JButton();
        jBTReserveren = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jCBzoekGenre = new javax.swing.JComboBox();
        jCBzoekDatadrager = new javax.swing.JComboBox();
        jCBzoekUitvoering = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTNietBeschikbaar = new javax.swing.JTable();

        jTFToonAdres.setEnabled(false);

        jTFToonAchternaam.setEnabled(false);

        jLabel10.setText("Straatnaam");

        jTFToonVoornaam.setEnabled(false);

        jLabel9.setText("Achternaam");

        jLabel7.setFont(new java.awt.Font("Cambria", 0, 18)); // NOI18N
        jLabel7.setText("Zoek een Film");

        jLabel8.setText("Voornaam");

        jBTZoek.setText("Zoek");
        jBTZoek.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTZoekActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Cambria", 0, 18)); // NOI18N
        jLabel6.setText("Klantgegevens");

        jLabel12.setText("Woonplaats");

        jLabel11.setText("Huisnummer");

        jLabel13.setText("Telefoonnummer");

        jTFToonHuisnummer.setEnabled(false);

        jTFToonWoonplaats.setEnabled(false);

        jTFToonTelefoonnummer.setEnabled(false);

        jLabel2.setText("Artikelnummer");

        jLabel4.setText("Genre");

        jLabel3.setText("Titel");

        jLabel5.setText("Producent");

        jLabel1.setFont(new java.awt.Font("Cambria", 0, 36)); // NOI18N
        jLabel1.setText("Films");

        jLabel14.setText("Medium");

        jLabel15.setText("Klantnummer");

        jTFKlantNummer.setEnabled(false);

        jTFilms.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "ArtikelID", "Titel", "Uitvoering", "Medium", "Gereserveerd"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTFilms.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTFilms.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(jTFilms);
        if (jTFilms.getColumnModel().getColumnCount() > 0) {
            jTFilms.getColumnModel().getColumn(0).setResizable(false);
            jTFilms.getColumnModel().getColumn(0).setPreferredWidth(40);
            jTFilms.getColumnModel().getColumn(1).setResizable(false);
            jTFilms.getColumnModel().getColumn(1).setPreferredWidth(250);
            jTFilms.getColumnModel().getColumn(2).setResizable(false);
            jTFilms.getColumnModel().getColumn(2).setPreferredWidth(80);
            jTFilms.getColumnModel().getColumn(3).setResizable(false);
            jTFilms.getColumnModel().getColumn(3).setPreferredWidth(80);
            jTFilms.getColumnModel().getColumn(4).setResizable(false);
            jTFilms.getColumnModel().getColumn(4).setPreferredWidth(80);
        }

        jLabel16.setFont(new java.awt.Font("Cambria", 0, 18)); // NOI18N
        jLabel16.setText("Zoek resultaat");

        jBTVerhuren.setText("Verhuren");
        jBTVerhuren.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTVerhurenActionPerformed(evt);
            }
        });

        jBTReserveren.setText("Reserveren");
        jBTReserveren.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTReserverenActionPerformed(evt);
            }
        });

        jLabel17.setText("Uitvoering");

        jCBzoekUitvoering.setName(""); // NOI18N

        jLabel18.setFont(new java.awt.Font("Cambria", 0, 18)); // NOI18N
        jLabel18.setText("NIET BESCHIKBAAR");

        jTNietBeschikbaar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "ArtikelID", "Titel", "Uitvoering", "Medium", "Gereserveerd tot", "Verhuurd tot"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTNietBeschikbaar.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTNietBeschikbaar.getTableHeader().setReorderingAllowed(false);
        jScrollPane3.setViewportView(jTNietBeschikbaar);
        if (jTNietBeschikbaar.getColumnModel().getColumnCount() > 0) {
            jTNietBeschikbaar.getColumnModel().getColumn(0).setResizable(false);
            jTNietBeschikbaar.getColumnModel().getColumn(0).setPreferredWidth(40);
            jTNietBeschikbaar.getColumnModel().getColumn(1).setResizable(false);
            jTNietBeschikbaar.getColumnModel().getColumn(1).setPreferredWidth(250);
            jTNietBeschikbaar.getColumnModel().getColumn(2).setResizable(false);
            jTNietBeschikbaar.getColumnModel().getColumn(2).setPreferredWidth(80);
            jTNietBeschikbaar.getColumnModel().getColumn(3).setResizable(false);
            jTNietBeschikbaar.getColumnModel().getColumn(3).setPreferredWidth(80);
            jTNietBeschikbaar.getColumnModel().getColumn(4).setResizable(false);
            jTNietBeschikbaar.getColumnModel().getColumn(4).setPreferredWidth(80);
            jTNietBeschikbaar.getColumnModel().getColumn(5).setResizable(false);
            jTNietBeschikbaar.getColumnModel().getColumn(5).setPreferredWidth(80);
        }

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(129, 129, 129)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel1)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTFZoekTitel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel3)
                                            .addComponent(jTFZoekArtikelNummer, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(35, 35, 35)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jCBzoekGenre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel4))
                                                .addGap(37, 37, 37)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jCBzoekDatadrager, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel14))
                                                .addGap(29, 29, 29)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel17)
                                                    .addComponent(jCBzoekUitvoering, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(28, 28, 28)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel5)
                                                    .addComponent(jTFZoekProducent, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(1, 1, 1)
                                                .addComponent(jBTZoek, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel16)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jBTReserveren)
                                .addGap(18, 18, 18)
                                .addComponent(jBTVerhuren, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTFKlantNummer))
                                .addGap(21, 21, 21)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jTFToonVoornaam, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(24, 24, 24)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jTFToonAchternaam, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(24, 24, 24)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addComponent(jTFToonAdres, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(24, 24, 24)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTFToonHuisnummer))
                                .addGap(24, 24, 24)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12)
                                    .addComponent(jTFToonWoonplaats, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(24, 24, 24)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel13)
                                    .addComponent(jTFToonTelefoonnummer, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 737, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 737, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(132, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jLabel6)
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTFToonAdres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel15))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTFToonVoornaam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTFKlantNummer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel9)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTFToonAchternaam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTFToonHuisnummer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(29, 29, 29))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTFToonTelefoonnummer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTFToonWoonplaats, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(34, 34, 34)
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFZoekArtikelNummer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBTZoek))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel14)
                    .addComponent(jLabel17)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFZoekTitel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBzoekGenre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBzoekDatadrager, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBzoekUitvoering, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFZoekProducent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBTVerhuren)
                    .addComponent(jBTReserveren))
                .addGap(30, 30, 30)
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(63, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Zoekopdracht voor ingevulde velden.
     * @param evt 
     */
    private void jBTZoekActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTZoekActionPerformed

        String artikelnummer = "";
        String titel = "";
        Genre genre = null;
        Datadrager datadrager = null;
        Uitvoering uitvoering = null;
        String producent = "";
        //ArtikelFilm artfilm = null;
        if (!jTFZoekArtikelNummer.getText().isEmpty()) {
            artikelnummer = jTFZoekArtikelNummer.getText();
        } else {

            if (!jCBzoekGenre.getSelectedItem().equals("Selecteer")) {
                genre = (Genre) jCBzoekGenre.getSelectedItem();
            }

            if (!jCBzoekDatadrager.getSelectedItem().equals("Selecteer")) {
                datadrager = (Datadrager) jCBzoekDatadrager.getSelectedItem();
            }

            if (!jCBzoekUitvoering.getSelectedItem().equals("Selecteer")) {
                uitvoering = (Uitvoering) jCBzoekUitvoering.getSelectedItem();
            }

            if (!jTFZoekProducent.getText().isEmpty()) {
                producent = jTFZoekProducent.getText();
            }
            if (!jTFZoekTitel.getText().isEmpty()) {
                titel = jTFZoekTitel.getText();
            }
        }
        lijst = controlpanel.getAlleMatchesArtikel(artikelnummer, producent, titel, datadrager, uitvoering, genre);
        if (lijst.size() >0 ){
            this.updateTables(lijst);
        }else{
            JOptionPane.showMessageDialog(null, "Helaas, er is iets fout gegaan");
        }
            
        
    }//GEN-LAST:event_jBTZoekActionPerformed

    /**
     * Reservering opdracht, met geselecteerde velden en ingevulde waarde.
     * @param evt 
     */
    private void jBTReserverenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTReserverenActionPerformed
        boolean result = false;
        int rij = -1;
        rij = jTFilms.getSelectedRow();
        int klantnummer = klant.getKlantnummer();
        if (rij != -1) {
            int artikelnummer = Integer.parseInt(jTFilms.getModel().getValueAt(rij, 0).toString());
            boolean available = false;

            available = controlpanel.controleerReservering(artikelnummer);

            if (available) {
                Timestamp sqlDate = new Timestamp(new java.util.Date().getTime());
                result = controlpanel.maakReservering(artikelnummer, klantnummer, sqlDate);
                if (result) {
                    this.updateTables(lijst);
                    JOptionPane.showMessageDialog(null, "Reservering geplaatst", null, JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(null, "Fout, er is iets misgegaan met opslaan", null, JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Deze film is niet beschikbaar om te reserveren", null, JOptionPane.INFORMATION_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Er is geen selectie gemaakt", null, JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jBTReserverenActionPerformed

    /**
     * Verstuur verhuuropdracht met geselecteerde waarden. 
     * @param evt 
     */
    private void jBTVerhurenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTVerhurenActionPerformed
        DateTime artikelterugkeerdag = null;
        boolean result = false;
        int rij = -1;
        rij = jTFilms.getSelectedRow();
        int klantnummer = -1;
        klantnummer = klant.getKlantnummer();
        int artikelnummer = -1;

        if (rij != -1) {
            artikelnummer = Integer.parseInt(jTFilms.getModel().getValueAt(rij, 0).toString());
            artikelterugkeerdag = controlpanel.controleerAanwezigheid(artikelnummer);
            
            if (artikelterugkeerdag == null) {
                int dagen = Integer.parseInt(JOptionPane.showInputDialog("Aantal dagen: "));
                java.sql.Date verhuurDatum = new java.sql.Date(new java.util.Date().getTime());
                java.sql.Date verstrijkDatum = new java.sql.Date(verhuurDatum.getTime() + (dagen * 1000 * 60 * 60 * 24));
                result = controlpanel.verhurenArtikel(klantnummer, artikelnummer, verhuurDatum, verstrijkDatum);
                if (result) {
                    this.updateTables(lijst);
                    JOptionPane.showMessageDialog(null, "Gelukt, artikel verhuurd", null, JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(null, "Fout, er is iets misgegaan met opslaan", null, JOptionPane.INFORMATION_MESSAGE);
                }
            } else {

                DateTimeFormatter formatter = DateTimeFormat.forPattern("dd / MM / yyyy");
                String formattedDate = formatter.print(artikelterugkeerdag);
                JOptionPane.showMessageDialog(null, "Fout, het artikel is reeds verhuur tot " + formattedDate, null, JOptionPane.INFORMATION_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Er is geen selectie gemaakt", null, JOptionPane.INFORMATION_MESSAGE);
        }


    }//GEN-LAST:event_jBTVerhurenActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBTReserveren;
    private javax.swing.JButton jBTVerhuren;
    private javax.swing.JButton jBTZoek;
    private javax.swing.JComboBox jCBzoekDatadrager;
    private javax.swing.JComboBox jCBzoekGenre;
    private javax.swing.JComboBox jCBzoekUitvoering;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField jTFKlantNummer;
    private javax.swing.JTextField jTFToonAchternaam;
    private javax.swing.JTextField jTFToonAdres;
    private javax.swing.JTextField jTFToonHuisnummer;
    private javax.swing.JTextField jTFToonTelefoonnummer;
    private javax.swing.JTextField jTFToonVoornaam;
    private javax.swing.JTextField jTFToonWoonplaats;
    private javax.swing.JTextField jTFZoekArtikelNummer;
    private javax.swing.JTextField jTFZoekProducent;
    private javax.swing.JTextField jTFZoekTitel;
    private javax.swing.JTable jTFilms;
    private javax.swing.JTable jTNietBeschikbaar;
    // End of variables declaration//GEN-END:variables
}
